﻿@using Core.FrameWork.Models.Models.System
@model Core.AdminUI.V2.Models.RespAdminUser
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_LayoutInput.cshtml";
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
</head>
<body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <input type="hidden" name="Id" v-model="Id" value="@Model.Id" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="spanlb">*</span>用户名
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="Name" v-model="Name" value="@Model.Name" required lay-verify="required"
                                   placeholder="请输入用户名" autocomplete="off" class="layui-input" onfocus="this.placeholder = ''" onblur="this.placeholder = '请输入用户名'" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="spanlb">*</span>真实姓名
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="TrueName" v-model="TrueName" value="@Model.TrueName" required lay-verify="required"
                                   placeholder="请输入真实姓名" autocomplete="off" class="layui-input" onfocus="this.placeholder = ''" onblur="this.placeholder = '请输入真实姓名'" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            地址
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="Address" v-model="Address" value="@Model.Address"
                                   placeholder="请输入地址" autocomplete="off" class="layui-input" onfocus="this.placeholder = ''" onblur="this.placeholder = '请输入地址'" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            公司名称
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="Company" v-model="Company" value="@Model.Company"
                                   placeholder="请输入公司" autocomplete="off" class="layui-input" onfocus="this.placeholder = ''" onblur="this.placeholder = '请输入公司'" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="spanlb">*</span>电子邮箱
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="Email" v-model="Email" value="@Model.Email" placeholder="请输入电子邮箱" required lay-verify="email" autocomplete="off" readonly onfocus="this.removeAttribute('readonly'); this.placeholder = ''" class="layui-input" onblur="this.placeholder = '请输入电子邮箱'" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="spanlb">*</span>手机号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="Phone" v-model="Phone" value="@Model.Phone" lay-verify="required|phone" placeholder="请输入手机号" autocomplete="off" class="layui-input" onfocus="this.placeholder = ''" onblur="this.placeholder = '请输入手机号'" />
                        </div>
                    </div>
                    <div class="layui-form-item  " pane>

                        <label class="layui-form-label"><span class="spanlb">*</span>角色(多选)</label>

                        <div class="layui-input-block" id="userRoles">
                            @{
                                var allRoles = ViewBag.roleList as List<SysAspNetRoles>;
                                string roles = "";
                                foreach (var item in allRoles)
                                {
                                    if (Model.RoleIds.Contains(item.Id))
                                    {
                                        <input type="checkbox" checked lay-filter="rolescheck" name="role-@item.Id" id="role-@item.Id" value="@item.Id" title="@item.Name">
                                        roles += item.Id + ",";
                                    }
                                    else
                                    {
                                        <input type="checkbox" lay-filter="rolescheck" name="role-@item.Id" id="role-@item.Id" value="@item.Id" title="@item.Name">
                                    }


                                }
                                <input id="Roles" value="@roles" name="Roles" type="hidden" lay-verify="required" lay-reqText="请选择用户角色" v-model="Roles" />
                            }


                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                        lay-filter="user-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form', 'jquery'], function() {
            let form = layui.form;
            let $ = layui.jquery;
          //监听checkbox复选
        form.on('checkbox(rolescheck)', function (data) {
            var roles = "";
            $("#userRoles input[type='checkbox']:checked").each(function () {
                roles += $(this).val() + ",";

            });

            $("input[name='Roles']").val(roles);

        });
            form.on('submit(user-save)', function(data) {
                $.ajax({
                    url: 'Update',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function(result) {
                         if (result.Code == 200) {
                             layer.msg(result.Msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                parent.layer.close(parent.layer.getFrameIndex(window
                                    .name)); //关闭当前页
                                parent.layui.table.reload("user-table");
                            });

                    }
                    else
                    {
                        layer.msg(result.Msg, {
                                icon: 2,
                                time: 1000
                            });
                    }
                    }
                })
                return false;
            });
        })
    </script>
</body>
</html>